package br.com.massai.controller.handlers;

import java.io.Serializable;
import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import br.com.massai.view.enums.MailType;

public class SendMailThread implements Serializable, Runnable {

	private static final long serialVersionUID = 3952407705517315277L;

	private static final Logger LOG = LogManager.getLogger(SendMailThread.class);

	private SendMail mail;
	
	private String addressee;
	private String arg1;
	private String arg2;
	private String password;
	private MailType type;
	
	private String spreadsheetCode;
	private String department;
	private String accrualBasis;
	private String observation;
	private List<String> addressees;

	public SendMailThread(String addressee, String arg1, String arg2, String password, MailType type) {
		this.addressee = addressee;
		this.arg1 = arg1;
		this.arg2 = arg2;
		this.password = password;
		this.type = type;
	}

	public SendMailThread(String nameUserRequested, List<String> addressees, String spreadsheetCode, String department, String accrualBasis, String observation, MailType type) {
		this.arg1 = nameUserRequested;
		this.addressees = addressees;
		this.spreadsheetCode = spreadsheetCode;
		this.department = department;
		this.accrualBasis = accrualBasis;
		this.observation = observation;
		this.type = type;
	}

	@Override
	public void run() {
		try{
			mail = new SendMail();

			switch (type) {
				case REGISTER_USER:
					mail.sendMailRegister(addressee, arg1, arg2, password);
					break;
	
				case RESET_PASSWORD:
					mail.sendMailResetPassword(addressee, arg1, arg2, password);
					break;
	
				case REVISION_SPREADSHEET:
					mail.sendMailRevisionSpreadsheet(arg1, addressees, spreadsheetCode, department, accrualBasis, observation);
					break;
			}

		} catch (Throwable e) {
			LOG.error(e.getMessage(), e);
		}
	}
}